package com.yaoxuguang.concurrence.singletonAndThread.serialize;

import java.io.*;

/**
 * @author yaoxuguang
 * @Title: yao-interview
 * @Package com.yaoxuguang.concurrence.singletonAndThread.serialize
 * @Description: TODO
 * @date 2018年12月25日18:09
 */
public class SendAndRead {
    public static void main(String[] args) {
        try {
            MyObject object = MyObject.getObject();
            FileOutputStream fos = new FileOutputStream(new File("myObjectFile.txt"));
            ObjectOutputStream out = new ObjectOutputStream(fos);
            out.writeObject(object);
            out.close();
            fos.close();
            System.out.println(object.hashCode());
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }


        try {
            FileInputStream fis = new FileInputStream(new File("myObjectFile.txt"));
            ObjectInputStream in = new ObjectInputStream(fis);
            MyObject myObject = (MyObject) in.readObject();
            in.close();
            fis.close();
            System.out.println(myObject.hashCode());
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}
